package com.ruoyi.project.sales.orders.divide.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.sales.orders.divide.domain.OrderType;
import com.ruoyi.project.sales.orders.divide.mapper.OrderTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderTypeServiceImpl implements OrderTypeService {

    @Autowired
    private OrderTypeMapper orderTypeMapper;

    @Override
    public List<OrderType> selectOrderTypeList(OrderType orderType) {
        return orderTypeMapper.selectOrderTypeList (orderType);
    }

    @Override
    public String checkTypeNameUnique(OrderType orderType) {
        OrderType type=  orderTypeMapper.selectOne(orderType);

        if(type!=null){
            return UserConstants.ORDERTYPE_NAME_NOT_UNIQUE;
        }
        return UserConstants.ORDERTYPE_NAME_UNIQUE;
    }

    @Override
    public int insertType(OrderType orderType) {
        return orderTypeMapper.insert(orderType);
    }

    @Override
    public OrderType selectTypeById(Long tid) {
        return orderTypeMapper.selectById(tid);
    }

    @Override
    public int updateType(OrderType orderType) {
        return orderTypeMapper.update(orderType);
    }

    @Override
    public int deleteTypeByIds(String ids) {
        Long[] postIds = Convert.toLongArray (ids);
        return orderTypeMapper.deleteByIds(postIds);
    }
}
